/*
 * FileUpload.java
 *
 * Created on __DATE__, __TIME__
 */

package Consult.view;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

import javax.swing.JLabel;
import javax.swing.JOptionPane;


/**
 *
 * @author  __USER__
 */
public class FileUpload extends javax.swing.JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/** Creates new form FileUpload */
	public FileUpload() {
		initComponents();
		initJFileChooser1();

	}
	/**
	 * ��ʼ��initJFileChooser1 ��ȡ�ļ�
	 */
	public void initJFileChooser1(){
		jFileChooser1.showDialog(new JLabel(), "ѡ��");
		
		File file = jFileChooser1.getSelectedFile();
		if(file==null){
			return;
		}
		JOptionPane.showMessageDialog(null,"�ϴ�"+ file.getName());
		
		//ʹ��IO�����ļ�
		BufferedReader in =null;
		String s=null;
		try {
			 in = new BufferedReader(new FileReader(file)) ;
			 //Book b = null;
			 //in.readLine();//���Ե�һ�б�ͷ
			 while((s=in.readLine())!=null){
				 System.out.println(s);
				String[] arr = s.split("/");
				BookModel book = new BookModel();
				book.setBno(arr[0]);
				book.setName(arr[1]);
				book.setAuthor(arr[2]);
				book.setTname(arr[3]);
				book.setLent(arr[4]);
				//�ж�ͼ�����Ƿ��ظ�
				//ͼ������
				BookAddDao bad = new BookAddDao();
				bad.insertBook(book);
			
			 }
		} catch (Exception e) {
			// TODO Auto-generated catch block
			System.out.println("��������ļ�����Books.txt");
		}finally{
			try {
				in.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	//GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {
		jFileChooser1 = new javax.swing.JFileChooser();
		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
		
		jFileChooser1.setBackground(new java.awt.Color(102, 153, 255));
		jFileChooser1.setFont(new java.awt.Font("΢���ź�", 0, 18));
		jFileChooser1.setForeground(new java.awt.Color(0, 204, 255));

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addComponent(
				jFileChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, 516,
				javax.swing.GroupLayout.PREFERRED_SIZE));
		layout.setVerticalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addComponent(
				jFileChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, 355,
				javax.swing.GroupLayout.PREFERRED_SIZE));

		pack();
	}// </editor-fold>
	//GEN-END:initComponents

	/**
	 * @param args the command line arguments
	 */
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new FileUpload().setVisible(true);
			}
		});
	}

	//GEN-BEGIN:variables
	// Variables declaration - do not modify
	private javax.swing.JFileChooser jFileChooser1;
	// End of variables declaration//GEN-END:variables

}